from django.contrib import admin

# Register your models here.
from .models import User, Complain, Result

# 自定义user管理页面
class UserAdmin(admin.ModelAdmin):
    def type(self):
        if self.type:
            return 'staff'
        else:
            return 'customer'
    # 列表页显示属性
    list_display = ['pk', 'username', 'email', 'mobile', type]
    list_filter = ['type']
    list_per_page = 10
    search_fields = ['username', 'mobile', 'email']
    # 添加修改页属性
    fieldsets = [
        ('account', {'fields': ['username', 'password', 'last_login', 'date_joined']}),
        ('info', {'fields': ['first_name', 'last_name', 'email', 'mobile', 'id_number', 'address']}),
        ('else', {'fields': ['type']})
    ]

admin.site.register(User,UserAdmin)

class ComplainAdmin(admin.ModelAdmin):
    list_display = ['pk', 'user', 'title', 'content']
    list_filter = ['user']

admin.site.register(Complain, ComplainAdmin)

class ResultAdmin(admin.ModelAdmin):
    list_display = ['user', 'content', 'complain']
    list_filter = ['user']

admin.site.register(Result, ResultAdmin)